﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace HYRElectric.LightningCalculation
{
	internal class TriangleVertex
	{
		public PointF Point { get; set; }

		public int ID { get; set; }

		public TriangleVertex()
		{
		}

		public TriangleVertex(TriangleVertex tv)
		{
			this.Point = tv.Point;
			this.ID = tv.ID;
		}

		public TriangleVertex(PointF point)
		{
			this.Point = point;
		}

		public static int GetYMinPoint(List<TriangleVertex> points)
		{
			int result = 0;
			double num = (double)points[0].Point.Y;
			for (int i = 0; i < points.Count; i++)
			{
				if (num > (double)points[i].Point.Y)
				{
					result = i;
					num = (double)points[i].Point.Y;
				}
			}
			return result;
		}

		public static void GetAssortedPoints(List<TriangleVertex> points)
		{
			new List<TriangleVertex>();
			int yminPoint = TriangleVertex.GetYMinPoint(points);
			TriangleVertex triangleVertex = points[yminPoint];
			points.Remove(triangleVertex);
			for (int i = 0; i < points.Count; i++)
			{
				for (int j = i + 1; j < points.Count - 1; j++)
				{
					if (TriangleVertex.GetCos(triangleVertex, points[i]) > TriangleVertex.GetCos(triangleVertex, points[j]))
					{
						TriangleVertex value = points[i];
						points[i] = points[j];
						points[j] = value;
					}
				}
			}
			points.Insert(0, triangleVertex);
		}

		public static double GetCos(TriangleVertex p1, TriangleVertex p2)
		{
			double num = Math.Sqrt(TriangleEdge.LengthSquare(p1, p2));
			return (double)(p2.Point.X - p1.Point.X) / num;
		}

		public static bool PointsEqual(PointF point1, PointF point2)
		{
			return point1.X == point2.X && point1.Y == point2.Y;
		}
	}
}
